package com.syslight.annotationdemo;

import android.os.Message;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.squareup.otto.Produce;
import com.syslight.annotationdemo.bus.OttoBus;

import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

@EActivity(R.layout.activity_one)
public class OneActivity extends ActionBarActivity {

    @ViewById
    Button buttonCallback;
    @ViewById
    Button buttonProduce;

    @Bean
    OttoBus bus;

    @Click({R.id.button_produce, R.id.button_callback})
    void onClick(View view) {
        switch (view.getId()) {
            case R.id.button_callback:
                Log.e("Activity", "before call OttoBus.post!");
                bus.post(new Message());
                Log.e("Activity", "after call OttoBus.post!");
                break;
            case R.id.button_produce:
                Log.e("Activity", "before call OttoBus.post produce!");
                bus.post(produceMessage());
                Log.e("Activity", "after call OttoBus.post produce!");
                break;
            default:
                break;
        }
    }

    @Produce
    public Message produceMessage() {
        Log.e("Activity", "produce message!");
        return new Message();
    }
}
